# ##############################################################################
# vendor/semidrive/drivers/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements.  See the NOTICE file distributed with this work for
# additional information regarding copyright ownership.  The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License.  You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

set(MCAL_INCDIR
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/include
    ${CMAKE_CURRENT_LIST_DIR}/devices/E3600M/E3650/include
    ${CMAKE_CURRENT_LIST_DIR}/devices/common/include
    ${CMAKE_CURRENT_LIST_DIR}/devices/common/gic/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Base/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Base/E3600M/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dio/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Lin/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/McuExt/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/McuLp/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Port/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Uart/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Wdg/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/OsIf/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/mram
    ${CMAKE_CURRENT_LIST_DIR}/platform/Rte/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Det/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eep/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Ea/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/mbox
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Port/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dma/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Rte/include
    ${CMAKE_CURRENT_LIST_DIR}/configs/arch/armv8-r52/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/include
    ${CMAKE_CURRENT_LIST_DIR}/vcos/eth_wrapper/
    ${CMAKE_CURRENT_LIST_DIR}/platform/Can/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dpe/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/include
    ${CMAKE_CURRENT_LIST_DIR}/vcos/can_wrapper/
    ${NUTTX_DIR}/../../drivers/can/e3/e3xx/
    ${NUTTX_DIR}/../../drivers/ETH/MAC/e3xx/e3650/
    ${NUTTX_DIR}/../../drivers/ETH/MAC/e3xx/e3650/
    ${NUTTX_DIR}/../../components/rt_framework/inc/
    ${CMAKE_CURRENT_LIST_DIR}/platform/OsIf/include)

set(MCAL_CSRCS
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Dio_Cfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Mcu_Cfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Ea_Cfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Eep_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/McuExt_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Port_Cfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Uart_Cfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Lin_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Dma_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Eth_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Can_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/Spi_PbCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/boards/E3650_dev_kit/output/src/EthTrcv_PBCfg.c
    ${CMAKE_CURRENT_LIST_DIR}/configs/arch/armv8-r52/arm_irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eep/src/Eep_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eep/src/Eep.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Ea/src/Ea.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Ea/src/Ea_Crc16.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Ea/src/Ea_Ops.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dio/src/Dio_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dio/src/Dio.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Lin/src/Lin_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Lin/src/Lin_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Lin/src/Lin_Uart.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Lin/src/Lin.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Ckgen.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_CkgenDrv.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Clk.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_ClkCfgNode.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_KickCore.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Pll.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_PllDrv.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Reset.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_ResetDrv.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_ResetSig.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Rstgen.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Soc.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu_Xtal.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Mcu/src/Mcu.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Uart/src/Uart_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Uart/src/Uart_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Uart/src/Uart.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_Scr.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_Cache.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_MemLibc.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_Delay.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/mram/Mram_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/Semag/Semag.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_Soc.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_MemLibc.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_Delay.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Port/src/Port_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Port/src/Port.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Rte/src/SchM_Base.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/OsIf/src/OsIf.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dma/src/Dma_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dma/src/Dma_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dma/src/Dma.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/desc_op.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/dwmac_hw.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/dwmac.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/Eth.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/EthBuff.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Eth/src/EthDesc.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/src/EthTrcv.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/src/dp83848.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/src/q21xx.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/src/rtl820f.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/EthTrcv/src/rtl9010x.c
    ${CMAKE_CURRENT_LIST_DIR}/vcos/eth_wrapper/EthIf.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Can/src/Can.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Can/src/Can_IP.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Can/src/Can_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/vcos/can_wrapper/CanIf.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/dpe/Dpe_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dpe/src/Dpe.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/src/Spi_Driver.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/src/Spi_Ip.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/src/Spi_Irq.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/src/Spi_Mld.c
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/src/Spi.c
    ${CMAKE_CURRENT_LIST_DIR}/vcos/e3650_ea.c
    ${CMAKE_CURRENT_LIST_DIR}/vcos/e3650_board.c)

set(MCAL_ASM_SRCS
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_CacheAsm.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_ArchOpt.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/Mcal_DelayAsm.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/memcpy_opt.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/McalLib/src/memclr_opt.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/src/mram/Mram_IpAsm.S
    ${CMAKE_CURRENT_LIST_DIR}/platform/OsIf/src/OsIf_s.S)

set(MCAL_C_FLAGS -DARCH_armv8_r -DCPU_cortex_r52 -DE3600 -DE3650 -D__ARM_ARCH=8 -DCFG_TTY_UART=UART_CHANNEL_UART15
               -DCFG_MULTI_CORE_SMP -DCFG_ARCH_FPU -DCFG_MEMCPY_ASM_OPTIMIZED -DCFG_MEMCLR_ASM_OPTIMIZED -DCFG_NOT_USED_AUTOSAR_OS
               -DCFG_DEBUG_LEVEL=1 -DCFG_PLATFORM_MCAL -DFUSALIB_IT -DFUSA_PLATFORM_MCAL -DGCOV_ENABLE -DCFG_IRG_LOG -DENABLE_DMA
               -DMRAM_TEST -DFLS_TEST -UGCOV_ENABLE -DCFG_STARTUP_LP -DCFG_MCULP_MODULE_EN -DSTD_AR_RELEASE_MAJOR_VERSION=4 -DSTD_AR_RELEASE_MINOR_VERSION=3
               -DPLATFORM_AR_RELEASE_MAJOR_VERSION=4 -DPLATFORM_AR_RELEASE_MINOR_VERSION=3 -DMCAL_AR_RELEASE_MAJOR_VERSION=4 -DMCAL_AR_RELEASE_MINOR_VERSION=3
               -DMCAL_AR_RELEASE_REVISION_VERSION=0 -DMCAL_AR_RELEASE_PATCH_VERSION=0 -DDET_AR_RELEASE_MAJOR_VERSION=4 -DDET_AR_RELEASE_MINOR_VERSION=3
               -DCOMPILER_AR_RELEASE_MAJOR_VERSION=4 -DCOMPILER_AR_RELEASE_MINOR_VERSION=3 -DCOMPILER_AR_RELEASE_REVISION_VERSION=0
               -DCOMPILER_AR_RELEASE_PATCH_VERSION=0 -DDET_AR_RELEASE_REVISION_VERSION=0 -DDET_AR_RELEASE_PATCH_VERSION=0 -DCFG_MCAL_DET_ENABLED
               -DLIN_CONFIGURATION_VARIANT_PRECOMPILE=1 -DLIN_CONFIGURATION_VARIANT_LINKTIME=2 -DLIN_CONFIGURATION_VARIANT_POSTBUILD_LOADABLE=3
               -D__ARMCC_VERSION=920
               -Wno-undef
               -Wno-shadow
               -Wno-strict-prototypes)
               

set(MCAL_ASM_FLAGS -DARCH_armv8_r -DCPU_cortex_r52 -DE3600 -DE3650 -D__ARM_ARCH=8 -DCFG_MULTI_CORE_SMP -DCFG_ARCH_TCM
                   -DCFG_SOC_RAM_ECC -DCFG_ARCH_FPU -DCFG_ARCH_LLPP_EN -DASSEMBLY -DCFG_PLATFORM_MCAL)

nuttx_add_library(mcal_c STATIC)
target_sources(mcal_c PRIVATE ${MCAL_CSRCS})
target_include_directories(mcal_c PRIVATE ${MCAL_INCDIR})
target_compile_options(mcal_c PRIVATE ${MCAL_C_FLAGS})

nuttx_add_library(mcal_asm STATIC)
target_sources(mcal_asm PRIVATE ${MCAL_ASM_SRCS})
target_include_directories(mcal_asm PRIVATE ${MCAL_INCDIR})
target_compile_options(mcal_asm PRIVATE ${MCAL_ASM_FLAGS})


set(VENDOR_THIRD_PARTY_DRIVER_INCDIR
    ${CMAKE_CURRENT_LIST_DIR}/devices/E3600M/E3650/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Uart/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Can/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Dpe/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Base/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/lld/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Spi/include
    ${CMAKE_CURRENT_LIST_DIR}/platform/Base/include CACHE INTERNAL "vendor third party driver incdir")

set(VENDOR_THIRD_PARTY_DRIVER_C_FLAGS ${MCAL_C_FLAGS} CACHE INTERNAL "vendor third party driver c flags")

set(VENDOR_THIRD_PARTY_DRIVER_ASM_FLAGS ${MCAL_ASM_FLAGS} CACHE INTERNAL "vendor third party driver asm flags")

target_include_directories(nuttx PRIVATE ${VENDOR_THIRD_PARTY_DRIVER_INCDIR})
target_include_directories(arch PRIVATE ${VENDOR_THIRD_PARTY_DRIVER_INCDIR})